package com.ylbh.modules.statistics.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.exception.NormalException;
import com.ylbh.common.pojo.statistics.dto.OperationStatisticsDTO;
import com.ylbh.common.pojo.statistics.vo.MembershipVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.statistics.service.OperationStatisticsService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 运营统计
 * @author czx
 */
@RestController
@RequestMapping("statistics")
public class OperationStatisticsController {

    @Autowired
    private OperationStatisticsService operationStatisticsService;

    @ApiOperation("所有类型用户数据统计")
    @RequestMapping("queryUserType")
    @RequiresPermissions("statistics:queryUserType")
    public CommonResult<List<Integer>> queryUserType(OperationStatisticsDTO operationStatisticsDTO) {
        List<Integer> type = operationStatisticsService.queryUserType(operationStatisticsDTO);
        return Ref.ok(type);
    }

    @ApiOperation("类型下的所有用户")
    @RequestMapping("queryUser")
    @RequiresPermissions("statistics:queryUser")
    public CommonResult<PageUtils> queryUser(OperationStatisticsDTO operationStatisticsDTO) {
        PageUtils user = operationStatisticsService.queryUser(operationStatisticsDTO);
        return Ref.ok(user);
    }

    @ApiOperation("运营统计")
    @PostMapping("queryMembership")
    @RequiresPermissions("statistics:queryUserType")
    public CommonResult<List<MembershipVO>> queryMembership(OperationStatisticsDTO operationStatisticsDTO) {
        List<MembershipVO> user = operationStatisticsService.queryMembership(operationStatisticsDTO);
        return Ref.ok(user);
    }

    @ApiOperation("运营统计下的各类型下的下级")
    @PostMapping("queryMembershipLower")
    @RequiresPermissions("statistics:queryUser")
    public CommonResult<PageUtils> queryMembershipLower(OperationStatisticsDTO operationStatisticsDTO) {
        PageUtils list = operationStatisticsService.queryMembershipLower(operationStatisticsDTO);
        return Ref.ok(list);
    }

    @ApiOperation("运营统计导出")
    @RequestMapping("exportMembershipLowerExcel")
    public CommonResult exportMembershipLowerExcel(HttpServletRequest request, HttpServletResponse response) throws NormalException {
        operationStatisticsService.exportMembershipLowerExcel(request, response);
        return Ref.ok();
    }
}
